package com.xmb.wechat.util;

import com.nil.sdk.utils.DateUtils;

import java.util.Calendar;
import java.util.Date;

/**
 * @Author lijiangop
 * @CreateTime 2020/5/27 17:50
 */
public class AliPayDateUtils {

    public static String getMonthDate(long time) {
        String monthAndDay = DateUtils.getStringByFormat(new Date(time), "MM-dd");
        String hourAndMinute = DateUtils.getStringByFormat(new Date(time), "HH:mm");
        String result = monthAndDay + "  " + hourAndMinute;

        Calendar todayCalendar = Calendar.getInstance();
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(time);

        if (todayCalendar.get(Calendar.YEAR) == calendar.get(Calendar.YEAR)) {//当年
            if (todayCalendar.get(Calendar.MONTH) == calendar.get(Calendar.MONTH)) {//当月
                int temp = todayCalendar.get(Calendar.DAY_OF_MONTH) - calendar.get(Calendar.DAY_OF_MONTH);
                switch (temp) {
                    case 0://今天
                        result = "今天 " + hourAndMinute;
                        break;
                    case 1://昨天
                        result = "昨天 " + hourAndMinute;
                        break;
                }
            }
        }
        return result;
    }
}
